home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / src-tk / Awindow.c next >
Encoding:
C/C++ Source or Header  |  1997-06-25  |  17.7 KB  |  745 lines

  1. /* $Id: Awindow.c 1.8 1997/06/25 19:17:47 StefanZ Exp StefanZ $*/
  2. /*
  3.  * (c) Copyright 1993, Silicon Graphics, Inc.
  4.  * ALL RIGHTS RESERVED
  5.  * Permission to use, copy, modify, and distribute this software for
  6.  * any purpose and without fee is hereby granted, provided that the above
  7.  * copyright notice appear in all copies and that both the copyright notice
  8.  * and this permission notice appear in supporting documentation, and that
  9.  * the name of Silicon Graphics, Inc. not be used in advertising
  10.  * or publicity pertaining to distribution of the software without specific,
  11.  * written prior permission.
  12.  *
  13.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  14.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  15.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  16.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  17.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  18.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  19.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  20.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  21.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  22.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  23.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  24.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  25.  *
  26.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  27.  */
  28.  
  29. /* Mesa tkAmiga by Stefan Z (d94sz@efd.lth.se)*/
  30.  
  31. /*$Log: Awindow.c $
  32.  * Revision 1.8  1997/06/25  19:17:47  StefanZ
  33.  * bumped to mesa 2.2
  34.  *
  35.  * Revision 1.5  1996/10/07  00:18:11  StefanZ
  36.  * Mesa 2.0 Fixed
  37.  *
  38.  * Revision 1.4  1996/08/14  22:53:16  StefanZ
  39.  * rev 1.3 tk fixes was from George 'Wulf' Krämer
  40.  *
  41.  * Revision 1.3  1996/08/14  22:23:31  StefanZ
  42.  * Modified due to api change in AmigaMesa
  43.  * Implemented div. Input modifier and changed windowhandling
  44.  *
  45.  * Revision 1.2  1996/06/02  00:03:03  StefanZ
  46.  * Started to use RCS to keep track of code.
  47.  *
  48.  */
  49. /*
  50. History:
  51.  
  52. 1.0 960315 Now almost evetything is implemented
  53. 1.1 960425 Fixed problem with double closeclicks (Thanx to Daniel Jönsson)
  54. 1.2 960731 Modified due to api change in AmigaMesa
  55. 1.3 Implemented div. Input modifier and changed windowhandling (Georg 'Wulf' Krämer)
  56.  
  57. TODO:
  58. Exposefunc
  59.  
  60.  
  61. */
  62.  
  63. //#define USE_CLIP_LAYER
  64. #undef USE_CLIP_LAYER
  65.  
  66.  
  67. #include <stdio.h>
  68. #include <stdlib.h>
  69. #include <string.h>
  70.  
  71. #include <intuition/intuition.h>
  72. #include <devices/inputevent.h>
  73. #ifdef __GNUC__
  74. #include <inline/exec.h>
  75. #include <inline/intuition.h>
  76. #include <inline/graphics.h>
  77.  
  78. #ifdef USE_CLIP_LAYER
  79. #include <inline/layers.h>
  80. #endif
  81. #else
  82. #include <proto/exec.h>
  83. #include <proto/intuition.h>
  84. #include <proto/graphics.h>
  85.  
  86. #ifdef USE_CLIP_LAYER
  87. #include <proto/layers.h>
  88. #endif
  89. #endif
  90.  
  91. #include "gltk.h"
  92. #include "GL/AmigaMesa.h"
  93.  
  94.  
  95.  
  96. #define static
  97.  
  98. #if defined(__cplusplus) || defined(c_plusplus)
  99. #define class c_class
  100. #endif
  101.  
  102. #if DBG
  103. #define TKASSERT(x)                                     \
  104. if ( !(x) ) {                                           \
  105.     PrintMessage("%s(%d) Assertion failed %s\n",        \
  106.         __FILE__, __LINE__, #x);                        \
  107. }
  108. #else
  109. #define TKASSERT(x)
  110. #endif  /* DBG */
  111.  
  112. /* Some Bitmasks for Amigaevents */
  113. #define ControlMask         (IEQUALIFIER_CONTROL)
  114. #define ShiftMask           (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)
  115. #define MousePressedMask    (SELECTDOWN | MENUDOWN | MIDDLEDOWN)
  116.  
  117. /******************************************************************************/
  118.  
  119. struct wnd 
  120.     {
  121.     int x, y, width, height;
  122.     GLenum type;
  123.     struct amigamesa_context *context;
  124.     };
  125.  
  126. struct wnd win={0,0,100,100,TK_INDEX,NULL};
  127.  
  128.  
  129. /*
  130. struct Library *IntuitionBase;
  131. struct Library *GfxBase;
  132. */
  133. struct Screen *screen = NULL;
  134. struct Window *tkhwnd = NULL;
  135.  
  136. #ifdef USE_CLIP_LAYER
  137. struct Region *tkclipreg = NULL;
  138. #endif
  139.  
  140. /* Local prototypes */
  141. struct Region *clipWindow(struct Window *win,
  142.     LONG minX, LONG minY, LONG maxX, LONG maxY);
  143. struct Region *clipWindowToBorders(struct Window *win);
  144.  
  145.  
  146.  
  147. GLboolean tkPopupEnable = TRUE;
  148.  
  149. /* Fixed palette support.  */
  150. /*
  151. #define BLACK   PALETTERGB(0,0,0)
  152. #define WHITE   PALETTERGB(255,255,255)
  153. #define NUM_STATIC_COLORS   (COLOR_BTNHIGHLIGHT - COLOR_SCROLLBAR + 1)
  154. */
  155. static void (*ExposeFunc)(int, int)              = NULL;
  156. static void (*ReshapeFunc)(GLsizei, GLsizei)     = NULL;
  157. static void (*DisplayFunc)(void)                 = NULL;
  158. static GLenum (*KeyDownFunc)(int, GLenum)        = NULL;
  159. static GLenum (*MouseDownFunc)(int, int, GLenum) = NULL;
  160. static GLenum (*MouseUpFunc)(int, int, GLenum)   = NULL;
  161. static GLenum (*MouseMoveFunc)(int, int, GLenum) = NULL;
  162. static void (*IdleFunc)(void)                    = NULL;
  163.  
  164. /*
  165.  *  Prototypes for the debugging functions go here
  166.  */
  167.  
  168. #define DBGFUNC 0
  169. #if DBGFUNC
  170.  
  171. static void DbgPrintf( const char *Format, ... );
  172. static void pwi( void );
  173. static void pwr(RECT *pr);
  174. /*static void ShowPixelFormat(HDC hdc);*/
  175.  
  176. #endif
  177.  
  178. #ifdef USE_CLIP_LAYER
  179. /* Get from clipping example of the RKM */
  180. /*
  181. ** clipWindow()
  182. ** Clip a window to a specified rectangle (given by upper left and
  183. ** lower right corner.)  the removed region is returned so that it
  184. ** may be re-installed later.
  185. */
  186. struct Region *clipWindow(struct Window *win,
  187.     LONG minX, LONG minY, LONG maxX, LONG maxY)
  188. {
  189. struct Region    *new_region;
  190. struct Rectangle  my_rectangle;
  191.  
  192. /* set up the limits for the clip */
  193. my_rectangle.MinX = minX;
  194. my_rectangle.MinY = minY;
  195. my_rectangle.MaxX = maxX;
  196. my_rectangle.MaxY = maxY;
  197.  
  198. /* get a new region and OR in the limits. */
  199. if (NULL != (new_region = NewRegion()))
  200.     {
  201.     if (FALSE == OrRectRegion(new_region, &my_rectangle))
  202.         {
  203.         DisposeRegion(new_region);
  204.         new_region = NULL;
  205.         }
  206.     }
  207.  
  208. /* Install the new region, and return any existing region.
  209. ** If the above allocation and region processing failed, then
  210. ** new_region will be NULL and no clip region will be installed.
  211. */
  212. return(InstallClipRegion(win->WLayer, new_region));
  213. }
  214.  
  215. /*
  216. ** clipWindowToBorders()
  217. ** clip a window to its borders.
  218. ** The removed region is returned so that it may be re-installed later.
  219. */
  220. struct Region *clipWindowToBorders(struct Window *win)
  221. {
  222. return(clipWindow(win, win->BorderLeft, win->BorderTop,
  223.     win->Width - win->BorderRight - 1, win->Height - win->BorderBottom - 1));
  224. }
  225. #endif
  226.  
  227. float tkRGBMap[8][3] = 
  228.     {
  229.     {   0, 0, 0 },
  230.     {   1, 0, 0 },
  231.     {   0, 1, 0 },
  232.     {   1, 1, 0 },
  233.     {   0, 0, 1 },
  234.     {   1, 0, 1 },
  235.     {   0, 1, 1 },
  236.     {   1, 1, 1 }
  237.     };
  238.  
  239. int atk_setIDCMPs(void)
  240.     {
  241.     int mask;
  242.     mask=IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE;
  243.     if (ReshapeFunc)
  244.         mask |=IDCMP_NEWSIZE;
  245.     if (KeyDownFunc)
  246.         mask |=(IDCMP_RAWKEY | IDCMP_VANILLAKEY);
  247.     if (MouseDownFunc||MouseUpFunc)
  248.         mask |=IDCMP_MOUSEBUTTONS;
  249.     if (MouseMoveFunc)
  250.         mask |= IDCMP_MOUSEMOVE;
  251.  
  252.     return(mask);
  253.     }
  254.  
  255. /* TODO (*ExposeFunc)(int, int)   */
  256.  
  257. void atk_modifyIDCMP(void)
  258.     {
  259.     if(tkhwnd)
  260.         {
  261.         ModifyIDCMP( tkhwnd, atk_setIDCMPs() );
  262.         }
  263.     }
  264.  
  265.  
  266. int atk_FixKeyRAW(char c)
  267.     {
  268.     int key;
  269.     switch (c) 
  270.         {
  271.         /*
  272.       case XK_Return:   key = TK_RETURN;    break;
  273.       case XK_Escape:   key = TK_ESCAPE;    break;
  274.         */
  275.       case CURSORLEFT:   key = TK_LEFT;      break;
  276.       case CURSORUP:     key = TK_UP;        break;
  277.       case CURSORRIGHT:  key = TK_RIGHT;     break;
  278.       case CURSORDOWN:   key = TK_DOWN;      break;
  279.       default:      key = GL_FALSE;     break;
  280.     }
  281.     return(key);
  282.     }
  283.  
  284.  
  285. /***************************************************************
  286.  *                                                             *
  287.  *  Exported Functions go here                                 *
  288.  *                                                             *
  289.  ***************************************************************/
  290.  
  291.  
  292. void tkNewCursor(GLint id, GLubyte *shapeBuf, GLubyte *maskBuf, GLenum fgColor,
  293.      GLenum bgColor, GLint hotX, GLint hotY)
  294. {
  295. /* cursor.c */ 
  296. }
  297.  
  298. void tkSetCursor(GLint id)
  299. {
  300. /* cursor.s*/
  301. }
  302.  
  303. void tkErrorPopups(GLboolean bEnable)
  304. {
  305.     tkPopupEnable = bEnable;
  306. }
  307.  
  308. void tkCloseWindow(void)
  309.     {
  310.     if (win.context) 
  311.         {
  312.         AmigaMesaDestroyContext(win.context);
  313.         win.context=NULL;
  314.         }
  315. #ifdef USE_CLIP_LAYER
  316.     if (tkclipreg)
  317.         {
  318.         tkclipreg = InstallClipRegion(tkhwnd->WLayer, tkclipreg);
  319.         DisposeRegion(tkclipreg);
  320.         tkclipreg = NULL;
  321.         }
  322. #endif
  323.     if (tkhwnd)
  324.         {
  325.         CloseWindow(tkhwnd);
  326.         tkhwnd=NULL;
  327.         }
  328.     /* we don't open them so don't close them /
  329.     if (GfxBase)
  330.         {
  331.         CloseLibrary(GfxBase);
  332.         GfxBase=NULL;
  333.         }
  334.     if (IntuitionBase)
  335.         {
  336.         CloseLibrary(IntuitionBase);
  337.         IntuitionBase=NULL;
  338.         }
  339.     */
  340.     }
  341.  
  342.  
  343.  
  344. //#define PL printf("%d\n",__LINE__);
  345.  
  346. void tkExec(void)
  347.     {
  348.     struct IntuiMessage *msg;
  349.     BOOL done = FALSE;
  350.     BOOL press=FALSE;
  351.     int key,id;
  352.     /* Redraw handling changed by Wulf 11. Aug. 96 to ensure the
  353.        same handling under all systems */
  354.     GLenum Redraw=GL_FALSE;
  355.  
  356. //printf("tkExec\n");
  357.  
  358.     if (ReshapeFunc)
  359.         {
  360.         (*ReshapeFunc)(tkhwnd->Width-tkhwnd->BorderLeft-tkhwnd->BorderRight-2, tkhwnd->Height-tkhwnd->BorderTop-tkhwnd->BorderBottom-2);
  361.         }
  362.  
  363.     if (DisplayFunc)
  364.         {
  365.         //printf("DisplayFunk\n");
  366.         (*DisplayFunc)();
  367.         }
  368.  
  369.  
  370.     while (!done)
  371.         {
  372.         if (msg = (struct IntuiMessage *)GetMsg(tkhwnd->UserPort))
  373.             {
  374.             id=msg->Class;
  375.                                     /*  printf("msg->Class=0x%x\n",id);*/
  376.             // after ReplyMsg, you are nolonger allowed to use msg !
  377.             switch (id)
  378.                 {
  379.                 case IDCMP_NEWSIZE:
  380.                                 /* Sizes should be adjusted by border, but painting isn't adjusted :-( */
  381.                         win.width=  tkhwnd->Width-tkhwnd->BorderLeft-tkhwnd->BorderRight-2;
  382.                         win.height= tkhwnd->Height-tkhwnd->BorderTop-tkhwnd->BorderBottom-2;
  383. #ifdef USE_CLIP_LAYER
  384.                         if (tkclipreg) // Get rid of last clipping region
  385.                             {
  386.                             DisposeRegion(InstallClipRegion(msg->IDCMPWindow->WLayer,NULL));
  387.                             }
  388.                         clipWindowToBorders(msg->IDCMPWindow);
  389. #endif
  390.                         ReplyMsg((struct Message *)msg);
  391.                         if (ReshapeFunc)
  392.                             (*ReshapeFunc)(win.width, win.height);
  393.                         Redraw = GL_TRUE;
  394.                         break;
  395.                 case IDCMP_RAWKEY:
  396.                         key= atk_FixKeyRAW(msg->Code);
  397.                         if (key && KeyDownFunc)
  398.                             {
  399.                             GLenum mask;
  400.                             mask = 0;
  401.                             if (msg->Qualifier & ControlMask)
  402.                                 mask |= TK_CONTROL;
  403.                             if (msg->Qualifier & ShiftMask)
  404.                                 mask |= TK_SHIFT;
  405.                             ReplyMsg((struct Message *)msg);
  406.                             Redraw = (*KeyDownFunc)(key, mask);
  407.                             } else
  408.                                 ReplyMsg((struct Message *)msg);
  409.                         break;
  410.                 case IDCMP_VANILLAKEY:
  411.                         if (KeyDownFunc)
  412.                             {
  413.                             GLenum mask;
  414.                             mask = 0;
  415.                             if (msg->Qualifier & ControlMask)
  416.                                 mask |= TK_CONTROL;
  417.                             if (msg->Qualifier & ShiftMask)
  418.                                 mask |= TK_SHIFT;
  419.                             key = msg->Code;
  420.                             ReplyMsg((struct Message *)msg);
  421.                             Redraw = (*KeyDownFunc)(key, mask);
  422.                             } else
  423.                                 ReplyMsg((struct Message *)msg);
  424.                         break;
  425.                 case IDCMP_MOUSEMOVE:
  426.                         if (MouseMoveFunc) {
  427.                             int x = msg->MouseX,y = msg->MouseY;
  428.                             ReplyMsg((struct Message *)msg);
  429.                             Redraw = (*MouseMoveFunc)(x,y,press);
  430.                         } else
  431.                             ReplyMsg((struct Message *)msg);
  432.                         break;                  
  433.                 case IDCMP_MOUSEBUTTONS:
  434.                      /* Buttonhandling changed Wulf 11.08.96 */
  435.                 /* printf("code=%x\n",(WORD)msg->Code); */
  436.                         {
  437.                         GLenum mask = 0;
  438.                         int x = msg->MouseX, y = msg->MouseY;
  439.                         switch (msg->Code)
  440.                             {
  441.                             case SELECTDOWN: case SELECTUP: mask |= TK_LEFTBUTTON; break;
  442.                             case MIDDLEDOWN: case MIDDLEUP: mask |= TK_MIDDLEBUTTON; break;
  443.                             case MENUDOWN: case MENUUP:     mask |= TK_RIGHTBUTTON; break;
  444.                             }
  445.                         if (msg->Qualifier & ControlMask)
  446.                             mask |= TK_CONTROL;
  447.                         if (msg->Qualifier & ShiftMask)
  448.                             mask |= TK_SHIFT;
  449.                         if ((msg->Code & MousePressedMask))
  450.                             {
  451.                             press=mask;
  452.                             if (MouseDownFunc) {
  453.                                 ReplyMsg((struct Message *)msg);
  454.                                 Redraw = (*MouseDownFunc)(x,y,mask);
  455.                             } else
  456.                                 ReplyMsg((struct Message *)msg);
  457.                             }
  458.                         else
  459.                             {
  460.                             if (MouseUpFunc)
  461.                                 {
  462.                                 ReplyMsg((struct Message *)msg);
  463.                                 Redraw = (*MouseUpFunc)(x,y,mask);
  464.                                 } else
  465.                                 ReplyMsg((struct Message *)msg);
  466.                             press=0;
  467.                             }
  468.                         }
  469.                         break;
  470.                 case IDCMP_REFRESHWINDOW:   /* Not entierly tested! Wulf 11.08.96 */
  471.                         BeginRefresh(msg->IDCMPWindow);  /* Refresh Gadgets */
  472.                         EndRefresh(msg->IDCMPWindow, TRUE);
  473.                         ReplyMsg((struct Message *)msg);
  474.                         if (ExposeFunc)
  475.                             (*ExposeFunc)(win.width, win.height);
  476.                         Redraw = GL_TRUE;
  477.                         break;
  478.                 case IDCMP_CLOSEWINDOW:
  479.                         ReplyMsg((struct Message *)msg);
  480.                         done = TRUE;
  481.                         break;
  482.                 default:
  483.                         ReplyMsg((struct Message *)msg);
  484.                         break;
  485.                 }
  486.             }
  487.                                 /* TODO Fill this with tests and call apropriate functions */
  488.             if (IdleFunc)
  489.                 {
  490.                 (*IdleFunc)();
  491.                 Redraw = GL_TRUE;
  492.                 }
  493.             if ((Redraw==GL_TRUE) && DisplayFunc) /* Redraw handling changed by Wulf 11. Aug. 96 */
  494.                 {
  495.                 (*DisplayFunc)();
  496.                 Redraw = GL_FALSE;
  497.                 }
  498.             if(!done && !IdleFunc)
  499.                 {
  500.                 WaitPort(tkhwnd->UserPort);
  501.                 }
  502.         }
  503.     tkQuit();      /* do not return after quit */
  504. }
  505.  
  506.  
  507. void tkExposeFunc(void (*Func)(int, int))
  508.     {
  509. /*  printf("ExposeFunc\n");*/
  510.     ExposeFunc = Func;
  511.     atk_modifyIDCMP();
  512.     }
  513.  
  514. void tkReshapeFunc(void (*Func)(GLsizei, GLsizei))
  515.     {
  516. /*  printf("ReshapeFunc\n");*/
  517.     ReshapeFunc = Func;
  518.     atk_modifyIDCMP();
  519.     }
  520.  
  521. void tkDisplayFunc(void (*Func)(void))
  522.     {
  523. /*  printf("DisplayFunc\n");*/
  524.     DisplayFunc = Func;
  525.     }
  526.  
  527. void tkKeyDownFunc(GLenum (*Func)(int, GLenum))
  528.     {
  529. /*  printf("KeyDownFunc\n");*/
  530.     KeyDownFunc = Func;
  531.     atk_modifyIDCMP();
  532.     }
  533.  
  534. void tkMouseDownFunc(GLenum (*Func)(int, int, GLenum))
  535.     {
  536. /*  printf("MouseDownFunc\n");*/
  537.     MouseDownFunc = Func;
  538.     atk_modifyIDCMP();
  539.     }
  540.  
  541. void tkMouseUpFunc(GLenum (*Func)(int, int, GLenum))
  542.     {
  543. /*  printf("MouseUpFunc\n");*/
  544.     MouseUpFunc = Func;
  545.     atk_modifyIDCMP();
  546.     }
  547.  
  548. void tkMouseMoveFunc(GLenum (*Func)(int, int, GLenum))
  549.     {
  550. /*  printf("MouseMoveFunc\n");*/
  551.     MouseMoveFunc = Func;
  552.     atk_modifyIDCMP();
  553.     }
  554.  
  555. void tkIdleFunc(void (*Func)(void))
  556.     {
  557. /*  printf("IdleFunc\n");*/
  558.     IdleFunc = Func;
  559.     }
  560.  
  561. void tkInitPosition(int x, int y, int width, int height)
  562.     {
  563.     win.x=x;
  564.     win.y=y;
  565.     win.width=width;
  566.     win.height=height;
  567.     }
  568.  
  569. void tkInitDisplayMode(GLenum type)
  570.     {
  571.     win.type = type;
  572.     }
  573.  
  574. GLenum tkInitWindow(char *title)
  575.     {
  576.     GLenum   Result =GL_FALSE,
  577.                 RGB_Flag    =GL_TRUE,
  578.                 DB_Flag =GL_FALSE;
  579.  
  580.     /* autocode opens and close libs
  581.     if (IntuitionBase = OpenLibrary("intuition.library",37))
  582.         {
  583.         if (GfxBase = OpenLibrary("graphics.library",37))
  584.             { */
  585.             if (!(screen = LockPubScreen("MESA")))
  586.                 screen = LockPubScreen(NULL);
  587.             if (screen)
  588.                 {
  589.                                             /* open the window on the public screen */
  590.  
  591.  
  592.                 tkhwnd = OpenWindowTags(NULL,
  593.                             WA_Left,  win.x,            WA_Top,    win.x,
  594.                             WA_InnerWidth, win.width,   WA_InnerHeight, win.height,
  595.                             WA_DragBar,                 TRUE,
  596.                             WA_CloseGadget,         TRUE,
  597.                             WA_SizeGadget,          TRUE,
  598.                             WA_DepthGadget,         TRUE,
  599.                             WA_SmartRefresh,            TRUE,
  600.                             WA_ReportMouse,         TRUE,
  601.                             WA_NoCareRefresh,           TRUE,
  602.                             WA_RMBTrap,                 TRUE, /* Detect right mouse events, no Menus */
  603.                             WA_SizeBBottom,         TRUE,
  604.                             WA_MinWidth,100,        WA_MinHeight,30,
  605.                             WA_MaxWidth,-1,         WA_MaxHeight,-1,
  606.                             WA_IDCMP,               atk_setIDCMPs(),
  607.                             WA_Flags,               WFLG_SIZEGADGET | WFLG_DRAGBAR,
  608.                             WA_Title,               title,
  609.                             WA_PubScreen,               screen,
  610.                             TAG_END);
  611.                                             /* Unlock the screen.  The window now acts as a lock on
  612.                                             ** the screen, and we do not need the screen after the
  613.                                             ** window has been closed.  */
  614.                 UnlockPubScreen(NULL, screen);
  615.                 if (tkhwnd)
  616.                     {
  617. #ifdef USE_CLIP_LAYER
  618.                     tkclipreg = clipWindowToBorders(tkhwnd);
  619. #endif
  620.                     if (win.type & TK_INDEX)
  621.                         {
  622.                         RGB_Flag=GL_FALSE;
  623.                         }
  624.                     if (win.type & TK_DOUBLE)
  625.                         {
  626.                         DB_Flag=GL_TRUE;
  627.                         }
  628.  
  629.                     win.context=AmigaMesaCreateContextTags(
  630.                             AMA_DrawMode,                       AMESA_AGA,
  631.                             AMA_Window,(unsigned long)      tkhwnd,
  632.                             AMA_RastPort,(unsigned long)    tkhwnd->RPort,
  633.                             AMA_Screen,(unsigned long)      tkhwnd->WScreen,
  634.                             AMA_DoubleBuf,                      DB_Flag,
  635.                             AMA_RGBMode,                        RGB_Flag,
  636.                             AMA_Left,                           tkhwnd->BorderLeft,
  637.                             AMA_Bottom,                         tkhwnd->BorderBottom+1,
  638.                             TAG_DONE,0);
  639.  
  640.                     AmigaMesaMakeCurrent(win.context,win.context->buffer);
  641.                     return GL_TRUE;
  642.                     }
  643.                 else
  644.                     {
  645.                     printf("Failed to open window.\n");
  646.                     return(Result);
  647.                     }
  648.                 }
  649. /*          }   
  650.         }  */
  651. }
  652.  
  653.  
  654.  
  655. /******************************************************************************/
  656.  
  657. /*
  658.  * You cannot just call DestroyWindow() here.  The programs do not expect
  659.  * tkQuit() to return;  DestroyWindow() just sends a WM_DESTROY message
  660.  */
  661.  
  662. void tkQuit(void)
  663. {
  664.     tkCloseWindow();
  665.    exit(0);    /*TODO*/
  666. }
  667.  
  668. /******************************************************************************/
  669.  
  670. void tkSetOneColor(int index, float r, float g, float b)
  671. {
  672.     AmigaMesaSetOneColor(win.context,index,r,g,b);
  673. }
  674.  
  675. void tkSetFogRamp(int density, int startIndex)
  676. {
  677. /* TODO */
  678. printf("tkSetFogRamp(%d,%d) TODO\n",density,startIndex);
  679. }
  680.  
  681. void tkSetGreyRamp(void)
  682. {
  683.  /* TODO */
  684. printf("tkSetGreyRamp() TODO\n");
  685.  
  686. }
  687.  
  688. void tkSetRGBMap( int Size, float *Values )
  689. {
  690. /* TODO */
  691. printf("tkSetRGBMap(%d,%f) TODO\n",Size,*Values);
  692. }
  693.  
  694. void tkSetOverlayMap(int size, float *rgb)
  695. {
  696. printf("tkSetOverlayMap(%d,%f) TODO\n",size,rgb);
  697. }
  698. /******************************************************************************/
  699.  
  700. void tkSwapBuffers(void)
  701. {
  702.   AmigaMesaSwapBuffers(win.context);
  703. }
  704.  
  705. /******************************************************************************/
  706.  
  707. GLint tkGetColorMapSize(void)
  708. {
  709.  /* TODO */
  710.     printf("tkGetColorMapSize() TODO\n");
  711.     return(255);
  712. }
  713.  
  714. void tkGetMouseLoc(int *x, int *y)
  715. {
  716.     *x = tkhwnd->MouseX;
  717.     *y = tkhwnd->MouseY;
  718. }
  719.  
  720.  
  721. GLenum tkGetDisplayMode(void)
  722. {
  723.     return win.type;
  724. }
  725.  
  726. GLenum tkSetWindowLevel(GLenum level)
  727. {
  728. printf("tkSetWindowLevel(%d) TODO\n",level);
  729. return GL_FALSE;
  730. }
  731.  
  732. /*
  733. TK_RGBImageRec *tkRGBImageLoad(char *fileName)
  734. {
  735. printf("tkRGBImageLoad(%s) TODO\n",fileName);
  736. }
  737. */
  738.  
  739. void tkGetSystem(TKenum type, void *ptr)
  740. {
  741. printf("tkGetSystem(%d,*ptr) TODO\n",type);
  742. /* getset.c */
  743. }
  744. #undef USE_CLIP_LAYER
  745.